﻿using System;

namespace AMC.SubstitutionCache.Rendering
{
    public class SubstitutionShapeRenderingInfo : IEquatable<SubstitutionShapeRenderingInfo>
    {
        public SubstitutionShapeRenderingInfo(Type contentPartType, string shapeType, string groupId)
        {
            ContentPartType = contentPartType;
            ShapeType = shapeType;
            GroupId = groupId;
        }

        public Type ContentPartType { get; private set; }
        public string ShapeType { get; private set; }
        public string GroupId { get; set; }

        #region IEquatable<SubstitutionShapeRenderingInfo>

        public static bool operator ==(SubstitutionShapeRenderingInfo left, SubstitutionShapeRenderingInfo right)
        {
            return Equals(left, right);
        }

        public static bool operator !=(SubstitutionShapeRenderingInfo left, SubstitutionShapeRenderingInfo right)
        {
            return !Equals(left, right);
        }

        public bool Equals(SubstitutionShapeRenderingInfo other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }

            if (ReferenceEquals(this, other))
            {
                return true;
            }

            return ContentPartType == other.ContentPartType && string.Equals(ShapeType, other.ShapeType) && string.Equals(GroupId ?? string.Empty, other.GroupId ?? string.Empty);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            var other = obj as SubstitutionShapeRenderingInfo;

            return other != null && Equals(other);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return ((ShapeType != null ? ShapeType.GetHashCode() : 0) * 397) ^ ((ContentPartType != null ? ContentPartType.GetHashCode() : 0) * 397) ^ (GroupId != null ? GroupId.GetHashCode() : 0);
            }
        }

        #endregion
    }
}